#pragma once
#include "base/count_down_cond.h"
#include "base/function.hpp"
#include "base/noncopyable.h"
#include "base/config.h"

#include <string>

#include <pthread.h>
namespace net_tools::base{

namespace detail{
class Thread_main;
} //namespace detail

class Thread : noncopyable{
friend class detail::Thread_main;
 public:
  Thread(func thread_begin_call,std::string thread_name = "DEFAULT NAME");
  ~Thread(){};
  void Start();
  //Don't use
  pthread_t GetThreadid() const {return threadid_;};
  static unsigned int GetThreadtid(){return thread_tid_;};
  static std::string* GetThreadname(){return p_thread_name_;};
  static __thread unsigned int thread_tid_;
  static __thread std::string* p_thread_name_;
 private:
  static void InitThreadtid();
  static void InitThreadname(std::string* thread_name);
  pthread_t       threadid_;
  func            thread_begin_call_;
  Count_down_cond Count_cond_;
  std::string*    thread_name_;
};

} //namespace net_tools::base